﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace sieuthi.Threelayer.DAL
{
    public class chitietDAL:VO.ketnoi
    {
        public List<VO.chitietVO> chitiet_xem()
        {
            List<VO.chitietVO> list = new List<VO.chitietVO>();
            using (SqlCommand dbCmd = new SqlCommand("chitiet_xem", GetConnection()))
            {
                VO.chitietVO obj = new VO.chitietVO();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.chitietIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        public bool chitiet_them(VO.chitietVO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("chitiet_them", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@gia", data.Gia));
                    dbCmd.Parameters.Add(new SqlParameter("@mahd", data.MaHD));
                    dbCmd.Parameters.Add(new SqlParameter("@mamh", data.MaMH));
                    dbCmd.Parameters.Add(new SqlParameter("@sl", data.SL));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }

            return true;
        }
        public bool chitiet_sua(VO.chitietVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("chitiet_sua", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@gia", data.Gia));
                dbCmd.Parameters.Add(new SqlParameter("@mahd", data.MaHD));
                dbCmd.Parameters.Add(new SqlParameter("@mamh", data.MaMH));
                dbCmd.Parameters.Add(new SqlParameter("@sl", data.SL));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool chitiet_xoa(string mahd)
        {
            using (SqlCommand dbCmd = new SqlCommand("chitiet_xoa", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@mahd", mahd));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
    }
}
